package core.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import org.apache.commons.lang.StringUtils;

public class DateConvertor {

	public static java.sql.Date convertToSqlDate(String str) {
		if (StringUtils.isBlank(str)) {
			return null;
		}

		SimpleDateFormat bartDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		try {
			java.util.Date date = bartDateFormat.parse(str);
			java.sql.Date sqlDate = new java.sql.Date(date.getTime());
			return sqlDate;
		} catch (ParseException e) {
			throw new RuntimeException(e);
		}
	}

	public static java.util.Date convertToUtilDate(String str) {
		if (StringUtils.isBlank(str)) {
			return null;
		}

		SimpleDateFormat bartDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		try {
			java.util.Date date = bartDateFormat.parse(str);

			return date;
		} catch (ParseException e) {
			throw new RuntimeException(e);
		}
	}

	public static java.sql.Date convertToSqlDate(java.util.Date date) {
		if (date == null) {
			return null;
		}

		java.sql.Date sqlDate = new java.sql.Date(date.getTime());
		return sqlDate;
	}

	public static java.util.Date convertToUtilDate(java.sql.Date sqlDate) {
		if (sqlDate == null) {
			return null;
		}
		
		java.util.Date date = new java.util.Date(sqlDate.getTime());

		return date;
	}
}
